package ast;

import compiler.OutputFormatter;

public class Attribution extends Statement {

    private Variable variable = null;
    private Expression expression = null;

    public Attribution(Variable var, Expression expr) {
        setVariable(var);
        setExpression(expr);
    }
    
    @Override
    public void genC(OutputFormatter of) {
        if (expression instanceof StringExpr) {
            of.output("string_attr(");
            expression.genC(of);
            of.output(", " + variable.getName() + ")");
        }
        else {
            of.output(variable.getName() + " = ");
            expression.genC(of);
        }
        super.genC(of);
    }

    public Expression getExpression() {
        return expression;
    }

    public Variable getVariable() {
        return variable;
    }

    public void setExpression(Expression expression) {
        this.expression = expression;
    }

    public void setVariable(Variable variable) {
        this.variable = variable;
    }

}
